In [1]:
from executeNotebook import execute_notebook
execute_notebook("Py4ET_2013_ECEM_Workshop.ipynb")

B. Scan Paths

Scan path overlay plots are generally created using either:

When a scan path overlay is sample based, areas of increased dwell time can usually be seen as the clustering of sample line segments within areas of the scene.

When an event based scan path is used, it is common for each fixation event to be plotted as a circle shape, often with each fixation circle diameter being scaled by the fixation event duration. Saccade events can be represented as lines joining the relevent surrounding fixation events, or fixations can simply be joined by lines anchored to each fixations center point, thereby not attempting to use any available saccadic information (angle, duration, etc.).

The scan path overlays to follow are created using an eye sample based approach.

To aid in the visualization of the temportal order of the sample scan trace, a color map is used, with the color ramp normalized to the start and end time of the sample data being plotted (the trial time). This is often a more effective way of relaying temporal information on the 2D scan path plot compared to cluttering the scan path with numbers giving the trial time of eveny Nth scan path segment, or the sample index, etc.

In [4]:
PLOT_SIZE=19,11
plt.rcParams['figure.figsize']=PLOT_SIZE

# For binocular recording 0 = Left eye, 1 = Right eye. Monocular recording should always use 0.
#
EYE_INDEX=0
    
# Select the ioDataStore hdf5 file to process.
# and load specified event type and event attribute values.
#
results_by_trial=loadSampleData(ET_WORKBOOK_INFO['event_type'],
                                         ET_WORKBOOK_INFO['event_fields'])

# Process sample streams for plotting
#
gaze_field_groups=ET_WORKBOOK_INFO['gaze_fields']
pupil_size_fields=ET_WORKBOOK_INFO['pupil_size_fields']

for trial_data in results_by_trial:
    invalid_data_masks=[]
    if EYE_TRACKER_USED=='SRR':
        invalid_data_masks.append(trial_data.pupil_measure1==0)
        
    elif EYE_TRACKER_USED=='TOBII':
        invalid_data_masks.append(trial_data.status//10>=2)
        invalid_data_masks.append(trial_data.status%10>=2)

    # Create Image background for each trial scanpath
    
    # get the condition variable set used for the current trial
    #
    condition_set=trial_data.condition_set
    
    # Get the image name used for display during the trial
    #
    image_name=condition_set.IMAGE_NAME
    trial_id=condition_set.trial_id
    # load the image
    #
    trial_image_array=numpy.flipud(mpimg.imread("./images/"+image_name))

    # Get background image size
    image_size=(trial_image_array.shape[1],trial_image_array.shape[0])
    ihw,ihh=image_size[0]/2,image_size[1]/2

    # Display image for illustrative purposes, 0,0 is image center.
    #
    plt.figure()
    bip=plt.imshow(trial_image_array,origin='lower',extent=(-ihw, ihw,-ihh, ihh))
    plt.title("Trial {0}: {1}".format(trial_id,image_name))
    
    x,y=getattr(trial_data,gaze_field_groups[EYE_INDEX][0]).copy(),getattr(trial_data,gaze_field_groups[EYE_INDEX][1]).copy()
    p=getattr(trial_data,pupil_size_fields[EYE_INDEX]).copy()
    time=trial_data.time
    
    valid_data_periods=processSampleEventGaps(x,y,p,invalid_data_masks[EYE_INDEX],'clear')

    sample_points = np.array([x, y]).T.reshape(-1, 1, 2)
    sample_segments = np.concatenate([sample_points[:-1], sample_points[1:]], axis=1)

    scan_path_line_collection = LineCollection(sample_segments, cmap=plt.get_cmap('YlOrRd'),
    norm=plt.Normalize(time.min(), time.max()))
    scan_path_line_collection.set_array(time)
    scan_path_line_collection.set_linewidth(2)

    plt.gca().add_collection(scan_path_line_collection)
    
    cb=plt.colorbar(scan_path_line_collection)
    cb.set_label("Trial Time (sec)") 

    plt.show()
    plt.clf()
    
plt.rcdefaults()
In []: